﻿//layui.use(function () {
//    var table = layui.table;
//    var layer = layui.layer;
//    var $ = layui.jquery;
$(function () {
    Show()
})
//机床列表
    function Show() {
        layui.use(function () {
            var table = layui.table;
            var layer = layui.layer;
            var $ = layui.jquery;
            var Name = $("#Name").val();
            var Num = $("#Num").val();
            var State = $("#State").val();

            console.log(table)
            // 点击批量删除按钮的事件处理
            $('#batch-delete-btn').click(function () {
                var checkStatus = table.checkStatus('carriertable');
                var equipmentId = checkStatus.data.map(function (item) { return item.equipmentId; });
                console.log(equipmentId)
                if (equipmentId.length === 0) { 
                    layer.msg('请至少选择一条要删除的数据', { icon: 2 });
                    return;
                }
                layer.confirm('确定要批量删除选中的 ' + equipmentId.length + ' 条数据吗？', function (index) {
                    console.log(equipmentId)
                    localStorage.setItem("Token", "")

                    // 发送Ajax请求到后端，传递选中的id数组进行删除操作"2024-12-24 10:01:13.34129+08" "[null]"
                    $.ajax({
                        url: '/Equipment/EquipmentsPiDelete', // 后端批量删除接口地址，根据实际调整
                        type: 'Post',
                        data: {
                            Data: JSON.stringify(equipmentId),
                            Token: localStorage.getItem("Token")
                        },
                        success: function (res) {
                            var res = JSON.parse(res)
                            console.log(res)
                            if (res.data > 0) {
                                layer.msg('批量删除成功', { icon: 1 });
                                Show()
                            } else {
                                layer.msg('批量删除失败：' + res.message, { icon: 2 });
                            }
                            layer.close(index);
                        },
                        error: function () {
                            layer.msg('请求出错，请稍后再试', { icon: 2 });
                            layer.close(index);
                        }
                    });
                });
            });
            // 先进行表格的初始渲染
            table.render({
                elem: '#carriertable',  // 表格元素的选择器
                page: {
                    limit: 5,
                    limits: [3, 5, 8, 10]
                },
                toolbar: '#toolbarDemo',
                defaultToolbar: ['exports'],
                cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'equipmentId', title: '车间id' },
                    { field: 'equipmentNumbering', title: '设备编号' },
                    { field: 'equipmentName', title: '设备名称' },
                    {
                        field: 'equipmentType', title: '设备类型', templet: function (d) {
                            var locations = ['', '设备一', '设备二', '设备三'];
                            return locations[d.equipmentType];
                        }
                    },
                    //{ field: 'equipmentImage', title: '设备图片' },
                    { field: 'equipmentProductionLine', title: '所在生产线' },
                    { field: 'equipmentProcurementData', title: '采购日期' },
                    {
                        field: 'equipmentState', title: '状态', templet: function (d) {
                            return d.equipmentState == 1 ? '正常' : '异常';
                        }
                    },
                    {
                        field: '', title: '操作', templet: function (d) {
                            return '<a class="layui-btn layui-btn-edit layui-btn-xs" onclick="editData(' + d.equipmentId + ')"><i class="layui-icon layui-icon-edit"></i>编辑</a> ' + '<a class="layui-btn layui-btn-edit layui-btn-xs" onclick="editFind(' + d.equipmentId + ')"><i class="layui-icon layui-icon-edit"></i>查看</a> ' +
                                '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="deleteData(' + d.equipmentId + ')"><i class="layui-icon layui-icon-delete"></i>删除</a>' + '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="stateData(' + d.equipmentId + ')">' +
                                '<i class="layui-icon layui-icon-delete"></i>' +
                                (d.equipmentState == '1' ? '停工' : '恢复') + '</a>';
                        }
                    }
                ]],
                // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
                // +
                //'<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="stateData(' + d.equipmentId + ')"><i class="layui-icon layui-icon-delete"></i>恢复</a>
                data: []
            });
            // 创建表格实例
            $.ajax({
                url: "/Equipment/EquipmentsShow",
                type: "get",
                data: {
                    pageIndex: 1,
                    pageSize: 100,
                    equipmentName: Name,
                    equipmentNumbering: Num,
                    equipmentState: State||0,
                },
                success: function (data) {
                    data = JSON.parse(data);
                    console.log(data.data.pageList);
                    // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                    table.reload('carriertable', {
                        page: {
                            limit: 5,
                            limits: [3, 5, 8, 10]
                        },
                        data: data.data.pageList
                    });
                },
                error: function () {
                    console.log("请求失败");
                }
            });
        });
    
}
 
//修改设备状态
window.stateData = function (equipmentId) {
    // 先根据id获取要编辑的数据，发起Ajax请求
    var form = layui.form;
    $.ajax({
        type: "get",
        url: "/Equipment/EquipmentsUpdateState",  // 替换为实际的后台根据id获取数据的接口地址
        data: { equipmentId: equipmentId, token: localStorage.getItem("token") },
        success: function (res) {
            var res = JSON.parse(res)
            if (res.data >= 1) {
                layer.alert("修改状态成功");
                Show();  // 重新加载数据，刷新表格显示
            } else {
                layer.alert("修改状态失败");

            }
        },
    });
}

//设备删除
window.deleteData = function (equipmentId) {
    console.log(equipmentId);
    layer.confirm('确定要删除该条数据吗？', function (index) {
        $.ajax({
            type: "Post",
            url: "/Equipment/EquipmentsDelete",  // 替换为实际的后台删除数据接口地址
            data: { data: JSON.stringify({ equipmentId: equipmentId }), token: localStorage.getItem("token") },
            success: function (res) {
                var res = JSON.parse(res)
                if (res.data >= 1) {
                    layer.alert("删除成功");
                    Show();  // 重新加载数据，刷新表格显示
                } else {
                    layer.alert("删除失败");

                }
            },
            error: function () {
                layer.msg('删除失败，请稍后重试', {
                    time: 2000,
                    icon: 2
                });
            }
        });
        layer.close(index);
    });
};


//查看跳转按钮
window.editFind = function (equipmentId) {
    localStorage["equipmentId"] = equipmentId
    location.href = "/Equipment/EquipmentsFinds";
}



//车间添加
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;
    var img = "";
    util.on('lay-on', {
        'test-page-custom': function () {
            layer.open({
                type: 1,
                title: "新增设备信息",
                content: `<form class="layui-form" style="padding:80px;">
                    <div class="layui-form-item">
                    <label class="layui-form-label">设备编号：</label>
                    <div class="layui-input-inline">
                    <input type="text" name="equipmentNumbering" id="equipmentNumbering" autocomplete="off" placeholder="请输入设备编号" class="layui-input">
                    </div>
                    </div>
                     <div class="layui-form-item">
                    <label class="layui-form-label">设备名称：</label>
                    <div class="layui-input-inline">
                    <input type="text" name="equipmentName" id="equipmentName" autocomplete="off" placeholder="请输入设备名称" class="layui-input">
                    </div>
                    </div>
                      <div class="layui-form-item">
                   <label class="layui-form-label">设备类型：</label>
                   <div class="layui-input-block">
                       <select name="equipmentType" id="equipmentType" required lay-verify="required">
                           <option value="">请选择</option>
                           <option value="1">类型一</option>
                           <option value="2">类型二</option>
                           <option value="3">类型三</option>
                       </select>
                   </div>
                    </div>
                     <div class="layui-form-item">
                   <label class="layui-form-label">状态: </label>
                   <div class="layui-input-inline">
                       <input type="radio" name="equipmentState"  value="1" checked>正常
                       <input type="radio" name="equipmentState"  value="2">异常
                   </div>
                   </div>
                    <div class="layui-form-item">
                   <label class="layui-form-label">所在生产线：</label>
                   <div class="layui-input-block">
                       <select name="equipmentProductionLine" id="equipmentProductionLine" required lay-verify="required">
                           <option value="">请选择</option>
                           <option value="生产线一">生产线一</option>
                           <option value="生产线二">生产线二</option>
                           <option value="生产线三">生产线三</option>
                       </select>
                   </div>
                    </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">采购日期</label>
                    <div class="layui-input-inline">
                        <input type="date" class="layui-input" name="equipmentProcurementData" id="equipmentProcurementData" placeholder="yyyy-MM-dd" lay-verify="date">
                    </div>
                </div>
                    <div class="layui-form-item">
                    <label class="layui-form-label">添加人：</label>
                    <div class="layui-input-inline">
                    <input type="text" name="equipmentAddPeople" id="equipmentAddPeople" autocomplete="off" placeholder="请输入添加人" class="layui-input">
                    </div>
                    </div>
                    <div class="layui-inline">
                    <label class="layui-form-label">添加日期</label>
                    <div class="layui-input-inline">
                        <input type="date" class="layui-input" name="equipmentAddData" id="equipmentAddData" placeholder="yyyy-MM-dd" lay-verify="date">
                    </div>
                </div>
                    <div class="layui-form-item">
                    <button type="button" class="layui-btn" id="ID-upload-demo-btn">
                      <i class="layui-icon layui-icon-upload"></i> 单图片上传
                    </button>
                    <div style="width: 132px;">
                      <div class="layui-upload-list">
                        <img class="layui-upload-img"  id="equipmentAddImage" style="width: 100%; height: 92px;">
                        <div id="ID-upload-demo-text"></div>
                      </div>
                      <div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="filter-demo">
                        <div class="layui-progress-bar" lay-percent=""></div>
                      </div>
                    </div>
                    <div class="layui-input-block">
                    <button class="layui-btn layui-btn-primary" id="cancelBtn">取消</button>
                     <button class="layui-btn" lay-submit lay-filter="demo-login">添加</button>
                    </div>
                    <form>`,
                success: function () {
                    layui.use(function () {
                        var upload = layui.upload;
                        var layer = layui.layer;
                        var element = layui.element;
                        var $ = layui.$;
                        // 单图片上传
                        var uploadInst = upload.render({
                            elem: '#ID-upload-demo-btn',
                            url: 'http://localhost:17162/api/Equipments/IFileImg', // 实际使用时改成您自己的上传接口即可。
                            //url:'/Equipment/EquipmentsImages',

                            before: function (obj) {
                                // 预读本地文件示例，不支持ie8
                                obj.preview(function (index, file, result) {
                                    $('#equipmentAddImage').attr('src', result); // 图片链接（base64）
                                });

                                element.progress('filter-demo', '0%'); // 进度条复位
                                layer.msg('上传中', { icon: 16, time: 0 });
                            },
                            done: function (res) {
                                console.log(res)
                                // 若上传失败
                                if (res.code > 0) {
                                    return layer.msg('上传成功');
                                    img = res.data
                                } else {
                                    $('#ID-upload-demo-text').html(''); // 置空上传失败的状态
                                    return layer.msg('上传失败');
                                }
                                // 上传成功的一些操作
                                // …
                            },
                            error: function () {
                                // 演示失败状态，并实现重传
                                var demoText = $('#ID-upload-demo-text');
                                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                                demoText.find('.demo-reload').on('click', function () {
                                    uploadInst.upload();
                                });
                            },
                            // 进度条
                            progress: function (n, elem, e) {
                                element.progress('filter-demo', n + '%'); // 可配合 layui 进度条元素使用
                                if (n == 100) {
                                    layer.msg('上传完毕', { icon: 1 });
                                }
                            }
                        });
                    });

                    // 对弹层中的表单进行初始化渲染
                    form.render();
                    // 表单提交事件
                    form.on('submit(demo-login)', function (data) {
                        var field = data.field;
                        delete field.file;
                        field.equipmentAddImage=img
                        console.log(field)
                        $.ajax({
                            url: '/Equipment/EquipmentsAdd',
                            type: 'post',
                            data: { data: JSON.stringify(field), token: localStorage.getItem("token") },
                            success: function (res) {
                                var s = JSON.parse(res)
                                console.log(res)
                                if (s.code == 1) {
                                    layer.alert("添加成功");
                                    setTimeout(function () {
                                        location.reload();
                                    }, 2000);
                                }
                                else {
                                    layer.alert("添加失败");
                                }
                            }
                        })
                        return false; // 阻止默认 form 跳转
                    });
                }
            });

        }
    })



//查看


//window.editFind = function (equipmentId) {
//    // 先根据id获取要编辑的数据，发起Ajax请求
//    var form = layui.form;
//    $.ajax({
//        type: "get",
//        url: "/Equipment/EquipmentsFind",  // 替换为实际的后台根据id获取数据的接口地址
//        data: { equipmentId: equipmentId, token: localStorage.getItem("token") },
//        success: function (res) {
//            var res = JSON.parse(res)
//            console.log(res)
//            $(res.data).each(function () {
//                $('#equipmentId').val(this.equipmentId)
//                //$('#equipmentSerialNumber').val(this.equipmentSerialNumber)
//                $('#equipmentName').val(this.equipmentName)
//                $('#equipmentNumbering').val(this.equipmentNumbering)
//                $('#equipmentType').val(this.equipmentType);
//                $('#equipmentProductionLine').val(this.equipmentProductionLine);

//                //反填下拉框要渲染
//                form.render('select');

//                // 反填单选框
//                var equipmentState = this.equipmentState;
//                $('input[name="equipmentState"][value="' + equipmentState + '"]').prop('checked', true);
//                // 反填采购日期
//                const dateValue = this.equipmentProcurementData;
//                const date = new Date(dateValue);
//                if (!isNaN(date.getTime())) {
//                    const formattedDate = date.toISOString().split('T')[0];
//                    document.getElementById('equipmentProcurementData').value = formattedDate;
//                } else {
//                    document.getElementById('equipmentProcurementData').value = ''; // 或者其他
//                }
//                $('#equipmentAddPeople').val(this.equipmentAddPeople)
//                // 反填添加日期
//                const dateValue2 = this.equipmentAddData;
//                const date2 = new Date(dateValue2);
//                if (!isNaN(date2.getTime())) {
//                    const formattedDate = date2.toISOString().split('T')[0];
//                    document.getElementById('equipmentAddData').value = formattedDate;
//                } else {
//                    document.getElementById('equipmentAddData').value = ''; // 或者其他
//                }
//                $('#equipmentImage').val(this.equipmentImage)
//                $('#addName').val(this.addName)
//                $('#addTime').val(this.addTime)
//                obj.equipmentId = this.equipmentId
//                //obj.equipmentSerialNumber = this.equipmentSerialNumber
//                obj.equipmentName = this.equipmentName
//                obj.equipmentNumbering = this.equipmentNumbering
//                obj.equipmentType = this.equipmentType
//                obj.equipmentState = this.equipmentState
//                obj.equipmentProductionLine = this.equipmentProductionLine
//                obj.equipmentProcurementData = this.equipmentProcurementData
//                obj.equipmentAddPeople = this.equipmentAddPeople
//                obj.equipmentAddData = this.equipmentAddData
//                obj.equipmentImage = this.equipmentImage
//                obj.addName = this.addName
//                obj.addTime = this.addTime
//                debugger
//            })
//        },
//    });

//    layer.open({
//        type: 1,
//        title: '编辑车间信息',
//        content: `<form class="layui-form" style="padding:30px;">
//                    <div class="layui-form-item">
//                    <label class="layui-form-label">设备编号：</label>
//                    <div class="layui-input-inline">
//                    <input type="text" name="equipmentNumbering" id="equipmentNumbering" autocomplete="off" placeholder="请输入设备编号" class="layui-input">
//                    </div>
//                    </div>
//                     <div class="layui-form-item">
//                    <label class="layui-form-label">设备名称：</label>
//                    <div class="layui-input-inline">
//                    <input type="text" name="equipmentName" id="equipmentName" autocomplete="off" placeholder="请输入设备名称" class="layui-input">
//                    </div>
//                    </div>
//                      <div class="layui-form-item">
//                   <label class="layui-form-label">设备类型：</label>
//                   <div class="layui-input-block">
//                       <select name="equipmentType" id="equipmentType" required lay-verify="required">
//                           <option value="">请选择</option>
//                           <option value="1">位置一</option>
//                           <option value="2">位置二</option>
//                           <option value="3">位置三</option>
//                       </select>
//                   </div>
//                    </div>
//                     <div class="layui-form-item">
//                   <label class="layui-form-label">状态: </label>
//                   <div class="layui-input-inline">
//                       <input type="radio" name="equipmentState"  value="1" checked>正常
//                       <input type="radio" name="equipmentState"  value="2">异常
//                   </div>
//                   </div>
//                    <div class="layui-form-item">
//                   <label class="layui-form-label">所在生产线：</label>
//                   <div class="layui-input-block">
//                       <select name="equipmentProductionLine" id="equipmentProductionLine" required lay-verify="required">
//                           <option value="">请选择</option>
//                           <option value="生产线一">生产线一</option>
//                           <option value="生产线二">生产线二</option>
//                           <option value="生产线三">生产线三</option>
//                       </select>
//                   </div>
//                    </div>
//                  <div class="layui-inline">
//                    <label class="layui-form-label">采购日期</label>
//                    <div class="layui-input-inline">
//                        <input type="date" class="layui-input" name="equipmentProcurementData" id="equipmentProcurementData" placeholder="yyyy-MM-dd" lay-verify="date">
//                    </div>
//                </div>
//                    <div class="layui-form-item">
//                    <label class="layui-form-label">添加人：</label>
//                    <div class="layui-input-inline">
//                    <input type="text" name="equipmentAddPeople" id="equipmentAddPeople" autocomplete="off" placeholder="请输入添加人" class="layui-input">
//                    </div>
//                    </div>
//                    <div class="layui-inline">
//                    <label class="layui-form-label">添加日期</label>
//                    <div class="layui-input-inline">
//                        <input type="date" class="layui-input" name="equipmentAddData" id="equipmentAddData" placeholder="yyyy-MM-dd" lay-verify="date">
//                    </div>
//                </div>
//                    <form>
//                    `,
//        area: ['700px', '400px'],
//        success: function () {
//            var obj1 = {
//                equipmentId: '',
//                equipmentSerialNumber: '',
//                equipmentName: '',
//                equipmentNumbering: '',
//                equipmentType: '',
//                equipmentState: '',
//                equipmentProductionLine: '',
//                equipmentProcurementData: '',
//                equipmentAddPeople: '',
//                equipmentAddData: '',
//                equipmentImage: '',
//                addName: '',
//                addTime: ''
//            };
//            console.log(obj1)
//            // 对弹层中的表单进行初始化渲染
//            form.render();
//            // 表单提交事件
//            form.on('submit(demo-login)', function (data) {
//                var field = data.field;
//                obj1.equipmentId = obj.equipmentId
//                obj1.equipmentSerialNumber = obj.equipmentSerialNumber
//                obj1.equipmentName = obj.equipmentName
//                obj1.equipmentNumbering = field.equipmentNumbering
//                obj1.equipmentType = field.equipmentType
//                obj1.equipmentState = field.equipmentState
//                obj1.equipmentProductionLine = field.equipmentProductionLine
//                obj1.equipmentProcurementData = field.equipmentProcurementData
//                obj1.equipmentAddPeople = field.equipmentAddPeople
//                obj1.equipmentAddData = field.equipmentAddData
//                obj1.equipmentImage = field.equipmentImage
//                obj1.addName = obj.addName
//                obj1.addTime = obj.addTime
//                $.ajax({
//                    url: '/Equipment/EquipmentsUpdate',
//                    type: 'post',
//                    data: { obj1, token: localStorage.getItem("token") },
//                    success: function (res) {
//                        var res = JSON.parse(res)
//                        console.log(field)
//                        console.log(res)
//                        if (res.data >= 1) {
//                            layer.alert("修改成功");
//                            setTimeout(function () {
//                                location.reload();
//                            }, 2000);
//                        }
//                        else {
//                            layer.alert("修改失败");
//                        }
//                    }
//                })
//                return false; // 阻止默认 form 跳转
//            });
//        }
//    });
//};


//修改

var obj = {
    equipmentId: '',
    //equipmentSerialNumber: '',
    equipmentName: '',
    equipmentNumbering: '',
    equipmentType: '',
    equipmentState: '',
    equipmentProductionLine: '',
    equipmentProcurementData: '',
    equipmentAddPeople: '',
    equipmentAddData: '',
    equipmentImage: '',
    //addName: '',
    //addTime: ''
}

window.editData = function (equipmentId) {
    // 先根据id获取要编辑的数据，发起Ajax请求
    $.ajax({
        type: "get",
        url: "/Equipment/EquipmentsFind",  // 替换为实际的后台根据id获取数据的接口地址
        data: { equipmentId: equipmentId, token: localStorage.getItem("token") },
        success: function (res) {
            var res = JSON.parse(res)
            console.log(res)
            $(res.data).each(function () {
                console.log(this.equipmentNumbering)
                //$('#equipmentId').val(this.equipmentId);
                $('#equipmentNumbering').val(this.equipmentNumbering);
                $('#equipmentName').val(this.equipmentName);
                $('#equipmentType').val(this.equipmentType);
                $('#equipmentProductionLine').val(this.equipmentProductionLine);

                //反填下拉框要渲染
                form.render('select');
                // 反填单选框
                var equipmentState = this.equipmentState;
                $('input[name="equipmentState"][value="' + equipmentState + '"]').prop('checked', true);
                // 反填采购日期
                const dateValue = this.equipmentProcurementData;
                const date = new Date(dateValue);
                if (!isNaN(date.getTime())) {
                    const formattedDate = date.toISOString().split('T')[0];
                    document.getElementById('equipmentProcurementData').value = formattedDate;
                } else {
                    document.getElementById('equipmentProcurementData').value = ''; // 或者其他
                }
                $('#equipmentAddPeople').val(this.equipmentAddPeople)
                // 反填添加日期
                const dateValue2 = this.equipmentAddData;
                const date2 = new Date(dateValue2);
                if (!isNaN(date2.getTime())) {
                    const formattedDate = date2.toISOString().split('T')[0];
                    document.getElementById('equipmentAddData').value = formattedDate;
                } else {
                    document.getElementById('equipmentAddData').value = ''; // 或者其他
                }
                $('#equipmentImage').val(this.equipmentImage)
                $('#addName').val(this.addName)
                $('#addTime').val(this.addTime)
                obj.equipmentId = this.equipmentId
                //obj.equipmentSerialNumber = this.equipmentSerialNumber
                obj.equipmentName = this.equipmentName
                obj.equipmentNumbering = this.equipmentNumbering
                obj.equipmentType = this.equipmentType
                obj.equipmentState = this.equipmentState
                obj.equipmentProductionLine = this.equipmentProductionLine
                obj.equipmentProcurementData = this.equipmentProcurementData
                obj.equipmentAddPeople = this.equipmentAddPeople
                obj.equipmentAddData = this.equipmentAddData
                obj.equipmentImage = this.equipmentImage
                obj.addName = this.addName
                obj.addTime = this.addTime
                debugger
            })
        },
    });

    layer.open({
        type: 1,
        title: '编辑车间信息',
        content: `<form class="layui-form" style="padding:30px;">
                    <div class="layui-form-item">
                    <label class="layui-form-label">设备编号：</label>
                    <div class="layui-input-inline">
                    <input type="text" name="equipmentNumbering" autocomplete="off" id="equipmentNumbering" placeholder="请输入设备编号" class="layui-input">
                    </div>
                    </div>
                     <div class="layui-form-item">
                    <label class="layui-form-label">设备名称：</label>
                    <div class="layui-input-inline">
                    <input type="text" name="equipmentName" id="equipmentName" autocomplete="off" placeholder="请输入设备名称" class="layui-input">
                    </div>
                    </div>
                      <div class="layui-form-item">
                   <label class="layui-form-label">设备类型：</label>
                   <div class="layui-input-block">
                       <select name="equipmentType" id="equipmentType" required lay-verify="required">
                           <option value="">请选择</option>
                           <option value="1">位置一</option>
                           <option value="2">位置二</option>
                           <option value="3">位置三</option>
                       </select>
                   </div>
                    </div>
                     <div class="layui-form-item">
                   <label class="layui-form-label">状态: </label>
                   <div class="layui-input-inline">
                       <input type="radio" name="equipmentState"  value="1" checked>正常
                       <input type="radio" name="equipmentState"  value="2">异常
                   </div>
                   </div>
                    <div class="layui-form-item">
                   <label class="layui-form-label">所在生产线：</label>
                   <div class="layui-input-block">
                       <select name="equipmentProductionLine" id="equipmentProductionLine" required lay-verify="required">
                           <option value="">请选择</option>
                           <option value="生产线一">生产线一</option>
                           <option value="生产线二">生产线二</option>
                           <option value="生产线三">生产线三</option>
                       </select>
                   </div>
                    </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">采购日期</label>
                    <div class="layui-input-inline">
                        <input type="date" class="layui-input" name="equipmentProcurementData" id="equipmentProcurementData" placeholder="yyyy-MM-dd" lay-verify="date">
                    </div>
                </div>
                    <div class="layui-form-item">
                    <label class="layui-form-label">添加人：</label>
                    <div class="layui-input-inline">
                    <input type="text" name="equipmentAddPeople" id="equipmentAddPeople" autocomplete="off" placeholder="请输入添加人" class="layui-input">
                    </div>
                    </div>
                    <div class="layui-inline">
                    <label class="layui-form-label">添加日期</label>
                    <div class="layui-input-inline">
                        <input type="date" class="layui-input" name="equipmentAddData" id="equipmentAddData" placeholder="yyyy-MM-dd" lay-verify="date">
                    </div>
                </div>
                    <div class="layui-input-block">
                    <button class="layui-btn layui-btn-primary" id="cancelBtn">取消</button>
                     <button class="layui-btn" lay-submit lay-filter="demo-login">修改</button>
                    </div>
                    <form>
                    `,
        area: ['700px', '400px'],
        success: function () {
            var obj1 = {
                equipmentId: '',
                //equipmentSerialNumber: '',
                equipmentName: '',
                equipmentNumbering: '',
                equipmentType: '',
                equipmentState: '',
                equipmentProductionLine: '',
                equipmentProcurementData: '',
                equipmentAddPeople: '',
                equipmentAddData: '',
                equipmentImage: '',
                addName: '',
                addTime: ''
            };
            console.log(obj1)
            // 对弹层中的表单进行初始化渲染
            form.render();
            // 表单提交事件
            form.on('submit(demo-login)', function (data) {
                var field = data.field;
                obj1.equipmentId = obj.equipmentId
                //obj1.equipmentSerialNumber = obj.equipmentSerialNumber
                obj1.equipmentName = field.equipmentName
                obj1.equipmentNumbering = field.equipmentNumbering
                obj1.equipmentType = field.equipmentType
                obj1.equipmentState = field.equipmentState
                obj1.equipmentProductionLine = field.equipmentProductionLine
                obj1.equipmentProcurementData = field.equipmentProcurementData
                obj1.equipmentAddPeople = field.equipmentAddPeople
                obj1.equipmentAddData = field.equipmentAddData
                obj1.equipmentImage = field.equipmentImage
                obj1.addName = obj.addName
                obj1.addTime = obj.addTime
                $.ajax({
                    url: '/Equipment/EquipmentsUpdate',
                    type: 'post',
                    data: { obj1, token: localStorage.getItem("token") },
                    success: function (res) {
                        var res = JSON.parse(res)
                        console.log(field)
                        console.log(res)
                        if (res.data >= 1) {
                            layer.alert("修改成功");
                            setTimeout(function () {
                                location.reload();
                            }, 2000);
                        }
                        else {
                            layer.alert("修改失败");
                        }
                    }
                })
                return false; // 阻止默认 form 跳转
            });
        }
    });
};

// 定义时间格式转换函数
function formatTime(timeStamp) {
    if (timeStamp) {
        var date = new Date(timeStamp);
        var year = date.getFullYear();
        var month = ('0' + (date.getMonth() + 1)).slice(-2);
        var day = ('0' + date.getDate()).slice(-2);
        var hour = ('0' + date.getHours()).slice(-2);
        var minute = ('0' + date.getMinutes()).slice(-2);
        var second = ('0' + date.getSeconds()).slice(-2);
        return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
    }
    return "";
}

//});



